<?php
namespace Sms;
class Sms
{
    private $sms_obj  ;
    public $api_list  ;

    /**
     * Sms constructor.
     * @param $api
     * @param $account
     * @param bool $type
     */
    public function __construct( $api , $account , $type =false )
    {
        //可用的api项
        $path = __DIR__.'/src' ;
        foreach(scandir($path) as $v)
        {
            if($v != '.' && $v!='..')
            {
                $api_ = explode('.', $v)[0];
                $this->api_list[strtolower($api_)] = $api_;
            }
        }
        $class = __NAMESPACE__."\\src\\".$this->api_list[strtolower($api)];
        $this->sms_obj = new $class($type ,$account );
    }

    /**
     *  信息发送
     * @param $to
     * @param $content
     * @param bool $sign
     * @return mixed array('error'=>'0|12|154','info'=>'成功|失败|不晓得','msgid'=>'1245144asdfg45asdfasfd','content'=>'您的验证码是.....')
     */
    public function send($to , $content ,$sign=false)
    {
        return $this->sms_obj->send($to,$content,$sign);
    }

    /**
     * 是否可以继续发送
     * @return true | false
     */
    public function isArrears()
    {
        return $this->sms_obj->isArrears();
    }

    /**array(
    'msgid'=>$v['msgid'],
    'phone'=>$v['phone'],
    'status'=>$v['status'],
    'desc'=>$v['desc']?:$this->get_code[$v['status']],
    'code'=>$v['wgcode'],
    );
     * @return mixed
     */
    public function getSendStatus()
    {
        return $this->sms_obj->getSendStatus();
    }

    /**
     * 余额查询
     * num : 剩余条数 ，amount:剩余金额
     * @return mixed => array('num'=>'12455','amount'=>'16.23');
     */
    public function balanceQuery()
    {
        return $this->sms_obj->balanceQuery();
    }
}
